﻿/**
 * 引用JS和CSS头文件
 */
var rootPath = getRootPath(); //项目路径

/**
 * 动态加载CSS和JS文件
 */
var dynamicLoading = {
    meta: function () {
        document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
        document.write('<meta name="viewport" content="width=device-width" />');
    },
    css: function (path) {
        if (!path || path.length === 0) {
            throw new Error('argument "path" is required!');
        }
        document.write('<link rel="stylesheet" type="text/css" href="' + path + '">');
    },
    js: function (path, charset) {
        if (!path || path.length === 0) {
            throw new Error('argument "path" is required!');
        }
        document.write('<script charset="' + (charset ? charset : "utf-8") + '" src="' + path + '"></script>');
    }
};

/**
 * 取得项目路径
 */
function getRootPath() {
    //取得当前URL
    var path = window.document.location.href;

    //取得主机地址后的目录
    var pathName = window.document.location.pathname;

    var post = path.indexOf(pathName);

    //取得主机地址
    var hostPath = path.substring(0, post);
    console.log("hostPath:" + hostPath);

    return hostPath;
}


/*
 获取时间戳,清缓存用
 */
var timestamp = Date.parse(new Date());


//动态生成meta
dynamicLoading.meta();

//动态加载项目 CSS文件
dynamicLoading.css(rootPath + "/fonts/iconfont.css");
dynamicLoading.css(rootPath + "/css/bootstrap.css");
dynamicLoading.css(rootPath + "/css/framebox.css");
dynamicLoading.css(rootPath + "/css/common.css");
//dynamicLoading.css(rootPath + "/lib/ztree/ztreestyle.css");
//dynamicLoading.css(rootPath + "/lib/icheck/skins/all.css");

//动态加载项目 JS文件
dynamicLoading.js(rootPath + "/lib/jquery/jquery.1.10.2.js", "utf-8");
dynamicLoading.js(rootPath + "/lib/jquery/jquery.cookie.js", "utf-8");
dynamicLoading.js(rootPath + "/lib/bootstrap/bootstrap.js", "utf-8");
dynamicLoading.js(rootPath + "//js/sellerscroll.js", "utf-8");
//dynamicLoading.js(rootPath + "/js/framebox.js", "utf-8");
dynamicLoading.js(rootPath + "/js/base.js", "utf-8");
dynamicLoading.js(rootPath + "/lib/dialog/dialog.yui.js", "utf-8");
dynamicLoading.js(rootPath + "/js/ui.js", "utf-8");
dynamicLoading.js(rootPath + "/js/util.js", "utf-8");

dynamicLoading.js(rootPath + "/lib/dot/dot.min.js", "utf-8");
dynamicLoading.js(rootPath + "/lib/validate/jquery.validate.js", "utf-8");
//dynamicLoading.js(rootPath + "/lib/ztree/jquery.ztree.all.js", "utf-8");

//$(function () {
//    $("#container").append('<div id="header"></div>');
//    $("#header").load(getRootPath() + "header.html");
//});
